﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///Members 的摘要说明
/// </summary>
public partial class Members
{
     DataTableDataContext db = new DataTableDataContext();

    //会员注册

        public int assertMembers( string aUserName,string aSex,
        int aAge, string aPassWord, string aQuestion, string aAnswer,
        string aAddress, string aPostcode, string aTel,
        string aEmail,DateTime aDatetime)
    {
        Members member = new Members 
        {
            userName= aUserName,
            sex= aSex,
            age=aAge,
            passWord=aPassWord,
            question=aQuestion,
            answer= aAnswer,
            adress= aAddress,
            postcode= aPostcode,
            tel= aTel,
            email=aEmail,
            createTime=aDatetime
        };
        db.Members.InsertOnSubmit(member);
        db.SubmitChanges();
        int id = member.userId;
        return id;
    }

    //返回所有的会员
    public IEnumerable<Members> GetAllMembers()
    {
        var members = from m in db.Members select m;
        return members;
    }
    //根据用户名返回会员信息
    public IEnumerable<Members> GetMembersByName(string name)
    {
        var members = from m in db.Members where m.userName == name select m;
        return members;
    }

    //删除会员信息
    public void removeMem(int id1)
    {
        var members = from m in db.Members where m.userId== id1 select m;
        var orderlists = from o in db.OrderList from m in db.Members where o.memberId == m.userId && m.userId == id1 select o;
        var orderdetails = from os in db.OrderDetail from o in db.OrderList from m in db.Members where o.orderListId == os.orderListId
                           && o.memberId == m.userId && m.userId == id1 select os;

        foreach (var orderdetail in orderdetails)
        {
            db.OrderDetail.DeleteOnSubmit(orderdetail);
            db.SubmitChanges();
        }
        foreach (var orderlist in orderlists)
        {
            db.OrderList.DeleteOnSubmit(orderlist);
            db.SubmitChanges();
        }
        foreach (var mem in members)
        {
            db.Members.DeleteOnSubmit(mem);
            db.SubmitChanges();
        }
        
    }


  
}